<script setup lang="ts">
import { onLoad } from "@dcloudio/uni-app";
import { ref } from "vue";
import goodsIcon from "./goodsIcon.vue";
import { onShow } from "@dcloudio/uni-app";
import { onReady } from "@dcloudio/uni-app";
import { router } from "@/utils/tools";
import { apiProductPage, getShopInfoPage } from "@/apis/product";
import { onReachBottom } from "@dcloudio/uni-app";
import goodsCard from "./goodsCard.vue";
import { useUserStore } from "@/stores/user";
const userStore = useUserStore();
const pageNum = ref(1);
const pageSize = ref(10);
const pageList = ref([]);
const leftList = ref([]);
const rightLists = ref([]);
const isMore = ref(false);

const props = defineProps(["orderField", "storeId"]);

const handleDetail = (row: any) => {
  router(`/pagesMerchand/stone-details?id=${row.id}`);
};

const getProductPage = async () => {
  let appUserId = null;
  if (userStore.userInfo === undefined) {
    appUserId = null;
  } else {
    appUserId = userStore.userInfo.id;
  }
  let res = await getShopInfoPage({
    pageNum: pageNum.value,
    pageSize: pageSize.value,
    // orderField: "default",
    // orderType: "desc",
    // appUserId:appUserId
    appUserId: props.storeId,
  });
  if (res.rows.length <= 0) {
    isMore.value = true;
    return false;
  }
  //console.log("========", res);
  pageNum.value++;
  // pageList.value = res.rows;
  handlePageList(res.rows);
};
const handlePageList = (data: any) => {
  for (let i = 0; i < data.length; i++) {
    data[i].images = data[i].images.split(",");
    data[i].videos = data[i].videos.split(",");
    if (i % 2 === 0) {
      leftList.value.push(data[i]);
    } else {
      rightLists.value.push(data[i]);
    }
  }

  //console.log("rightLists----", rightLists.value);
  //console.log("leftList----", leftList.value);
};
onReachBottom((e: any) => {
  getProductPage();
});
// 左侧数据
// const leftList = ref([])
// // 右侧数据
// const rightList = ref([])

const getData = () => {
  // for (let i = 0; i < props.lists.length; i++) {
  //   if (i % 2 === 0) {
  //     leftList.value.push(props.lists[i])
  //   } else {
  //     rightList.value.push(props.lists[i])
  //   }
  // }
};
onLoad((options: any) => {
  // 初始化数据
  getData();
});
onReady(() => {
  getProductPage();
});
</script>
<template>
  <view class="wf flex">
    <view class="wf-left flex flex-1 flex-column">
      <!-- 瀑布流左边 -->
      <view
        v-for="(item, i) in leftList"
        :key="i"
        @click="handleDetail(item)"
        class=""
      >
        <goodsCard :goodsData="item"> </goodsCard>
      </view>
    </view>
    <view class="flex wf-center"></view>

    <view class="wf-right flex flex-1 flex-column">
      <view
        v-for="(item, i) in rightLists"
        :key="i"
        @click="handleDetail(item)"
        class=""
      >
        <goodsCard :goodsData="item"> </goodsCard>
      </view>
    </view>
  </view>
  <uv-empty
    mode="list"
    marginTop="50rpx"
    v-if="leftList.length <= 0 && rightLists <= 0"
  ></uv-empty>
  <!-- <uv-load-more status="nomore" fontSize="12px" nomoreText="人家也是有底线哒" :line="true" v-if="isMore "  /> -->
  <!--  -->
</template>
<style scoped lang="scss">
.goods-icon {
  width: 100rpx;
  height: 100rpx;
  position: absolute;
  top: 20rpx;
  right: 20rpx;
}

.wf {
  .wf-center {
    width: 20rpx;
  }

  .wf-left {
    overflow: hidden;
  }

  .wf-right {
    overflow: hidden;
  }
}
</style>
